<?php

/**
 * Super class that all the Controller inherits of.
 * @abstract
 */
abstract class Controller
{
	private $output = '';
	private $css = array();
	private $js = array();
	private $ijs = '';
	private $title = '';
	private $name = '';

	protected $view;
	protected $model;
	
	abstract protected function DoControll();
	
	/**
    * function1 should never be overridden
    * @final
    */
	final public function __construct() {
		$this->Name( preg_replace( "/Controller$/i", "", get_class( $this ) ) );

		$viewName = ucfirst( strtolower( $this->Name() ) ) . "View";
		require_once "php/" . $viewName . ".php";
		$this->view = new $viewName();
		
		$modelName = ucfirst( strtolower( $this->Name() ) ) . "Model";
		require_once "php/" . $modelName . ".php";
		$this->model = new $modelName();

		$this->DoControll();
		
		$this->Output( $this->view->Markup() );
	}

	public function Output( $output = false )
	{
		if ( !$output )
		{
			return $this->output;
		}
		else
		{
			$this->output .= $output;
		}
	}

	public function IJS( $ijs = false )
	{
		if ( !$ijs )
		{
			return $this->ijs;
		}
		else
		{
			$this->ijs .= $ijs;
		}
	}
	
	public function CSS( $css = false )
	{
		if ( !$css )
		{
			return $this->css;
		}
		else
		{
			$this->css[] = $css;
		}
	}
	
	public function JS( $js = false )
	{
		if ( !$js )
		{
			return $this->js;
		}
		else
		{
			$this->js[] = $js;
		}
	}
	
	public function Title( $title = false )
	{
		if ( !$title )
		{
			return $this->title;
		}
		else
		{
			$this->title = $title;
		}
	}
	
	public function Name( $name = false )
	{
		if ( !$name )
		{
			return $this->name;
		}
		else
		{
			$this->name = $name;
		}
	}
}
